package com.elvish.efast.common.utils;

import com.elvish.efast.common.entity.Result;
import com.elvish.efast.common.enums.ResultCode;

/**
 * 结果处理工具类
 *
 * @author elvish
 * @date 2018/11/2 9:28
 * @blog oschina(https : / / my.oschina.net / xiaozhutefannao)
 */
public class ResultUtil {

    /**
     * 成功
     *
     * @param obj 对象
     * @return 结果对象
     */
    public static Result success(Object obj) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg("成功");
        result.setData(obj);
        return result;
    }

    /**
     * 成功
     *
     * @return 结果对象
     */
    public static Result success() {
        return success(null);
    }

    /**
     * 失败
     *
     * @param code 编码
     * @param msg  消息
     * @return 结果对象
     */
    public static Result fail(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    /**
     * 失败
     *
     * @param resultCode 结果编码对象
     * @return 结果对象
     */
    public static Result fail(ResultCode resultCode) {
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMsg(resultCode.getMsg());
        return result;
    }

}
